#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
class Solution
{
  public:
    int mem[N];
    int dp[N];
    int dfs(vector<int> &arr, int aim)
    {
        int n = arr.size();
        int res = 1e9;
        if (aim == 0)
            return 0;
        if (mem[aim])
            return mem[aim];
        for (int i = 0; i < n; i++)
        {
            if (aim >= arr[i])
                res = min(res, dfs(arr, aim - arr[i]) + 1);
        }
        return mem[aim] = res;
    }
    int minMoney(vector<int> &arr, int aim)
    {
        // int ans = dfs(arr, aim);
        // return ans == 1e9 ? -1 : ans;
        int n = arr.size();
        memset(dp, 0x3f, sizeof(dp));
        dp[0] = 0;
        for (int i = 1; i <= aim; i++)
        {
            for (int j = 0; j < n; j++)
            {
                if (i >= arr[j])
                    dp[i] = min(dp[i], 1 + dp[i - arr[j]]);
            }
        }
        return dp[aim] > 0x3f ? -1 : dp[aim];
    }
};